import axios from "@/api/Common/config";
import qs from "qs";
const pub = {
  // 发送请求
  http_post(server, fun, data) {
    return new Promise((r, e) => {
      console.log(6);
      axios
        .post(
          `http://www.tpblog.xin:8888/${server}/${fun}`,
          qs.stringify(data)
          // "username=root&password=root"
        )
        .then((res) => {
          r(res.data);
        });
    });
  },

  http_get(server, fun, data) {
    return new Promise((r, e) => {
      axios
        .get(`http://www.tpblog.xin:8888/${server}/${fun}`, { params: data })
        .then((res) => {
          r(res.data);
        });
    });
  },

  // 验证
  ch_phone(phone) {
    console.log(11111, phone);

    if (phone == "" || !/^13[2-90]\d{8}$/.test(phone) || phone.length < 11) {
      throw new Error("phone");
    }
  },
  ch_code(code, r_code) {
    if (r_code == "" || r_code != code) {
      throw new Error("code");
    }
  },
  ch_upwd(upwd) {
    if (upwd == "" || upwd.length < 6 || upwd.length > 16) {
      throw new Error("upwd");
    }
  },
  ch_check_upwd(upwd, check_upwd) {
    if (upwd == "" || upwd != check_upwd) {
      throw new Error("check_upwd");
    }
  },
  ch_uname(uname) {
    if (
      uname == "" ||
      !/^[\u4E00-\u9FA5A-Za-z0-9_]+$/.test(uname) ||
      uname.length >= 10
    ) {
      throw new Error("uname");
    }
  },
  ch_email(email) {
    if (
      email == "" ||
      !/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.com$/.test(email)
    ) {
      throw new Error("email");
    }
  },
};
export default pub;
